<!--修改销售机会  ————————  客户经理和销售主管可查看-->
<template>
  <div>
    <!--         Breadcrumbs -->
    <div class="breadcrumbs" style="margin: 0px;padding-top: 20px;">
      <ul>
        <li class="home"><a href="index.html" title="Go to Home Page"><strong style="font-size: 18px;">营销管理</strong></a>
          <span>/</span>
        </li>
        <li><strong>销售机会管理</strong><span>/</span></li>
        <li><strong>修改销售机会</strong></li>
      </ul>
    </div>
    <article class="col-main">
      <div class="my-account block block-account" style="padding-left: 20px;">

        <div class="page-title" style="border-bottom: #F1F3F6 1px solid;">
          <h2>修改销售机会</h2>
          <hr>
        </div>

        <form action="">

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">编号</strong>
            <div style="padding-left: 20px;">
              <input v-model="salesChances.saleId" readonly=“readonly” class="form-control" placeholder="" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">客户名称</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkCustomerName"  v-model="salesChances.customerName" class="form-control" placeholder="请输入客户名称" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">机会来源</strong>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkSaleSource" v-model="salesChances.saleSource" class="form-control" placeholder="请输入机会来源" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">成功几率</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkSuccessProbability" v-model="salesChances.successProbability" class="form-control" placeholder="请输入成功几率" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">概要</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <textarea v-on:blur="checkSaleOutline" v-model="salesChances.saleOutline" class="form-control" placeholder="请输入概要" style="width: 400px;"></textarea>
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">联系人</strong>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkContactsName" v-model="salesChances.contactsName" class="form-control" placeholder="请输入联系人" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">联系人电话</strong>
            <div style="padding-left: 20px;">
              <input v-on:blur="checkContactsTel1" v-model="salesChances.contactsTel1" class="form-control" placeholder="请输入联系人电话" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">机会描述</strong>
            <div style="padding-left: 20px;">
              <textarea v-on:blur="checkSaleDescribe" v-model="salesChances.saleDescribe" class="form-control" placeholder="请输入机会描述" style="width: 400px;"></textarea>
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">创建人</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <input v-model="salesChances.saleCreaterName" readonly=“readonly” class="form-control" placeholder="请输入创建人" style="width: 400px;">
            </div>
          </div>

          <div class="form-group">
            <strong style="font-weight: 1000;font-size: 20px">创建时间</strong>
            &nbsp;<span style="color: red;font-size: 15px">*</span>
            <div style="padding-left: 20px;">
              <input type="date" v-model="salesChances.saleDate" readonly=“readonly” class="form-control" placeholder="请输入创建时间" style="width: 400px;">
            </div>
          </div>

          <div class="text-center" style="margin-top: 40px;padding-bottom: 30px">
            <input v-on:click="updateSale" type="button" class="btn btn-primary" value="修改">
            <router-link to="SalesChanceList" class="btn btn-default">返回</router-link>
          </div>
        </form>

      </div>
    </article>
  </div>
</template>

<script>
export default {
  name: "UpdateSalesChance",
  data(){
    return{
      salesChances:[
        {
          saleId:"",
          customerName:"",//客户名称
          saleSource:"",//机会来源
          successProbability:"",//成功几率
          saleOutline:"",//概要
          contactsName:"",//联系人
          contactsTel1:"",//联系人电话
          saleDescribe:"",//机会描述
          saleCreater:"",//创建人
          saleDate:"",//创建时间
          saleCreaterName:''
        }
      ],
    }
  },
  methods:{
    getSaleById(){
      this.$axios.get("/sale/loadSale",{
        params:{
          saleId:this.$route.query.saleId
        }
      }).then(
        res=>{
          this.salesChances=res.data.data
          // console.log(res.data.data)
        }
      )
    },
    checkCustomerName(){
      if (this.salesChances.customerName == ''){
        this.$message({
          showClose: true,
          message: '客户名称不可为空',
          type: 'error'
        });
        return false;
      }else {
        return true;
      }
    },
    checkSaleSource(){
      if (this.salesChances.saleSource == ''){
        this.$message({
          showClose: true,
          message: '机会来源不可为空',
          type: 'error'
        });
        return false;
      }else {
        return true;
      }
    },
    checkSuccessProbability(){
      if (this.salesChances.successProbability == ''){
        this.$message({
          showClose: true,
          message: '成功几率不可为空',
          type: 'error'
        });
        return false;
      }else {
        return true;
      }
    },
    checkSaleOutline(){
      if (this.salesChances.saleOutline == ''){
        this.$message({
          showClose: true,
          message: '机会概要不可为空',
          type: 'error'
        });
        return false;
      }else {
        return true;
      }
    },
    checkContactsName(){
      if (this.salesChances.contactsName == ''){
        this.$message({
          showClose: true,
          message: '联系人不可为空',
          type: 'error'
        });
        return false;
      }else {
        return true;
      }
    },
    checkContactsTel1(){
      var reg = /^((13\d)|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[0,1,3,5,7,8])|(18[0-9])|(19[8,9]))\d{8}/;
      if (this.salesChances.contactsTel1 == ''){
        this.$message({
          showClose: true,
          message: '联系人电话不可为空',
          type: 'error'
        });
        return false;
      }else if (this.salesChances.contactsTel1.length != 11){
        this.$message({
          showClose: true,
          message: '用户电话格式不正确',
          type: 'error'
        });
        return false;
      }else if (!reg.test(this.salesChances.contactsTel1)){
        this.$message({
          showClose: true,
          message: '用户电话号码不存在',
          type: 'error'
        });
        return false;
      } else {
        return true;
      }
    },
    checkSaleDescribe(){
      if (this.salesChances.saleDescribe == ''){
        this.$message({
          showClose: true,
          message: '机会描述不可为空',
          type: 'error'
        });
        return false;
      }else {
        return true;
      }
    },
    updateSale(){
      if (this.checkCustomerName()){
        if (this.checkSaleSource){
          if (this.checkSuccessProbability){
            if (this.checkSaleOutline){
              if (this.checkContactsName){
                if (this.checkContactsTel1){
                  if (this.checkSaleDescribe){
                    this.$axios.put('/sale/updateSale',this.salesChances).then(
                      res=>{
                        this.$message({
                          showClose: true,
                          message: res.data.message,
                          type: 'success'
                        });
                      this.$router.push('/MemuBar/SalesChanceList')
                      }
                    )
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  created() {
    this.getSaleById()
  }
}
</script>

<style scoped>

</style>
